﻿package dt.inlee.system.service;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.metadata.ClassMetadata;
import org.springframework.stereotype.Service;

import dt.inlee.common.pagination.OrderBean;
import dt.inlee.common.pagination.PageBean;
import dt.inlee.common.pagination.SearchBean;
import dt.inlee.domain.OperationEntity;
import dt.inlee.system.dao.IOperationDao;

@Service("operationService")
public class OperationService {
	@Resource(name = "operationDao")
	private IOperationDao operationDao;


	/**
	 * Add a data
	 * 
	 * @param
	 * @return
	 */
	
	public String save(OperationEntity entity) {
		return operationDao.save(entity);
	}

	/**
	 * Update a data
	 * 
	 * @param
	 * @return
	 */
	public void update(OperationEntity entity) {
		operationDao.update(entity);
	}

	/**
	 * Show a data
	 * 
	 * @param id
	 * @return
	 */
	public OperationEntity getOperationById(String id) {
		return operationDao.get(id);
	}

	/**
	 * Delete an object by id
	 * 
	 * @param OperationBean
	 * @return
	 */
	public void deleteById(String id) {
		operationDao.delete(id);
	}

	public PageBean GetPage(SearchBean sb, int pageIndex, int pageSize) {

		PageBean pageBean = new PageBean();
		pageBean.setPageIndex(pageIndex);
		pageBean.setPageSize(pageSize);

		if (sb == null) {
			sb = new SearchBean();
		}
		//降序排列  拿ID排列
		OrderBean orderBean = new OrderBean("id", false);
		sb.addOrder(orderBean);

		pageBean.setParams(sb);
		this.operationDao.searchByPagination(pageBean);
		// total[0] = pageBean.getTotalData();
		return pageBean;
	}

	public List<OperationEntity> getList(SearchBean sb) {
		return this.operationDao.find(sb);
	}

	public ClassMetadata getMethodName(Object obj){
		return this.operationDao.methodName(obj);
	}
}
